import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { NzModalService } from 'ng-zorro-antd';
import { FetchService } from '../../../../../core/net/fetch.service';
import * as _ from 'lodash';
const stationHash = {
  '168': '跃进渠一所',
  '169': '跃进渠二所'
};
@Component({
  selector: 'app-gt-control-indicator',
  templateUrl: './gt-control-indicator.component.html',
  styleUrls: ['../gate-control-list.component.scss', './gt-control-indicator.component.scss']
})
export class GtControlIndicatorComponent implements OnInit {
  tableData = [];
  pageNum = 1;
  pageSize = 10;
  total: number;
  loading = false;
  searchForm: FormGroup;
  sectionList = [];
  controlList = [];
  rtuUrl = (window as any).environment.rtuUrl;
  constructor(private router: Router,
              private fb: FormBuilder,
              private http: HttpClient,
              private modalService: NzModalService,
              private fetchService: FetchService) {
    this.searchForm = this.fb.group({
      watergateCode: []
    });
  }

  ngOnInit(): void {
    this.queryInfo(true);
  }
  queryInfo(reset: boolean = false): void {
    if (reset) {
      this.pageNum = 1;
    }
    this.loading = true;
    const params = {
      ...this.searchForm.value,
      pageNum: this.pageNum,
      pageSize: this.pageSize
    };
    this.fetchService.post<Array<any>>('wrs/wrsBawaterGate/waterLevelInfo', params).subscribe(res => {
      const list = res || [];
      // const data = list.filter(item => {
      //     return !!item.info;
      // });
      this.tableData = list.map(row => {
        return {
          ...row,
          // stationName: stationHash[row.sectionId]
        };
      });
      this.total = res.length || 0;
      this.loading = false;
    });
  }
  directToSketchMap(): void {
    this.router.navigate(['/gate/gt-control']);
  }
}
